﻿using FolderTag.Model;
using System.Linq;

namespace FolderTag.DB.Dbo
{
    [SQLBuilder.Core.Attributes.Table("folder_path")]
    public class FolderPathDbo
    {
        /// <summary>
        /// 编号
        /// </summary>
        [SQLBuilder.Core.Attributes.Key]
        public int? Id { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Desc { get; set; }
        /// <summary>
        /// 路径
        /// </summary>
        public string Path { get; set; }
        /// <summary>
        /// 父路径
        /// </summary>
        public string ParentPath { get; set; }
        /// <summary>
        /// 标签列表
        /// </summary>
        public string TagIds { get; set; }

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static FolderPathDbo Create(PathItem pathItem)
        {
            FolderPathDbo result = new FolderPathDbo()
            {
                Id = pathItem.Id,
                Desc = pathItem.Desc,
                Path = pathItem.Path,
                ParentPath = pathItem.ParentPath,
                TagIds = string.Join(",", pathItem.TagList.Select(x => x.Id))
            };
            return result;
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static FolderPathDbo CreateNew(PathItem pathItem)
        {
            FolderPathDbo result = Create(pathItem);
            result.Id = null;
            return result;
        }
    }
}
